<?php

/**
 * ACoreBaseCollection
 *
 * @author Usenko Timur <usenko.timur@gmail.com>
 * @package base
 */

/**
 * @package base
 */
abstract class ACoreBaseCollection
{
	#<editor-fold defaultstate="collapsed" desc="private">
	/**
	 * @var array
	 */
	private $_aItems;
	#</editor-fold>

	/**
	 * @return ACoreBaseCollection
	 */
	public function __construct()
	{
		$this->_aItems = array();
	}
	
	/**
	 * @return array
	 */
	public function &GetAsArray()
	{
		return $this->_aItems;
	}

	/**
	 * @return array
	 */
	public function CloneAsArray()
	{
		return $this->_aItems;
	}

	/**
	 * @return mixed
	 */
	public function &GetByIndex($iIndex)
	{
		CCore::CheckTypes(array('$iIndex'));

		$mNull = null;
		if (key_exists($iIndex, $this->_aItems))
		{
			$mNull = $this->_aItems[$iIndex];
		}
		return $mNull;
	}
	
	/**
	 * @param mixed $mItem
	 * @return void
	 */
	public function Add($mItem)
	{
		CCore::CheckTypes(array('$mItem'));

		$this->_aItems[] = $mItem;
	}

	/**
	 * @param mixed $mItem
	 * @return void
	 */
	public function AddArray($aItems)
	{
		CCore::CheckTypes(array('$aItems'));

		if (is_array($aItems))
		{
			foreach ($aItems as $mItem)
			{
				$this->Add($mItem);
			}
		}
	}
	
	/**
	 * @return void
	 */
	public function Clear()
	{
		$this->_aItems = array();
	}
	
	/**
	 * @return int
	 */
	public function Count()
	{
		return count($this->_aItems);
	}
}
